<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="peoit" tagdir="/WEB-INF/tags" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<peoit:include>

	<div class="pd-20">
		<form action="<c:url value="/admin/role/roleAdd"/>" method="post" class="form form-horizontal" id="form-role-add">
			
			<div class="row cl">
				<label class="form-label col-2"><span class="c-red">*</span>角色名称：</label>
				<div class="formControls col-10">
					<input type="text" class="input-text" value=""  name="name"  placeholder="角色名称必须是位英文字符" datatype="s,*" errormsg="角色名称必须是位英文字符" nullmsg="角色名称不能为空">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2"><span class="c-red">*</span>描述：</label>
				<div class="formControls col-10">
					<input type="text" class="input-text"  placeholder="请输入描述" datatype="*" name="description">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2">权限：</label>
				<div class="formControls col-10">
					<c:forEach items="${viewData}" var="rolst">
						<c:if test="${rolst.level==2}" >
						<dl class="permission-list">
							<dd>
								<dl class="cl permission-list2">

										<c:set value="${rolst.id}" var="pId"></c:set>
									<dt>
										<label class="">
											<input type="checkbox" value="${rolst.id}" name="perId"  id="user-Character-0-0">
												${rolst.description}
										</label>
									</dt>

									<c:forEach items="${viewData}" var="rolst2">
										<c:if test="${pId == rolst2.parentPermissionId}">
										<dd>
											<label class="">
												<input type="checkbox" value="${rolst2.id}" name="perId"  datatype="need2"  id="user-Character-0-0-0">
													${rolst2.description}</label>
										</dd>
										</c:if>
									</c:forEach>

								</dl>

							</dd>
						</dl>
						</c:if>
					</c:forEach>
				</div>
			</div>
			<div class="row cl">
				<div class="col-10 col-offset-2">
					<button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
				</div>
			</div>
		</form>
	</div>

</peoit:include>
<script type="text/javascript">
	function refreshAndColse(){
		window.parent.location.href = window.parent.location;
	}
	$(function(){

		//表单验证ajax提交
		$("#form-role-add").Validform({
			tiptype:3,
			datatype: {//传入自定义datatype类型【方式二】;
				"need2": function (gets, obj, curform, regxp) {
					var need = 1,
							numselected = curform.find("input[name='" + obj.attr("name") + "']:checked").length;
					return numselected >= need ? true : "请至少选择一项！";
				}
			},
			callback:function(form){
				$("#form-role-add").ajaxSubFromDialog(this);
				setTimeout(refreshAndColse,1500);
				return false;
			}
		});

		$(".permission-list dt input:checkbox").click(function(){
			$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
		});
		$(".permission-list2 dd input:checkbox").click(function(){
			var l =$(this).parent().parent().find("input:checked").length;
			var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
			if($(this).prop("checked")){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
			}
			else{
				if(l==0){
					$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
				}
				if(l2==0){
					$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
				}
			}

		});
	});
</script>
</body>
</html>